<template>
  <view class="container"> 
    <view class="btn-list" v-for="(item, index) in groupList" :key="index">
      <view class="btn-item btn-red" @click="onBtnClick(item)">
        <image class="btn-icon" :src="item.thumb" mode="" />
      </view>
   
    </view>
  </view>
</template>
<script>
export default {
  data() {
    return {
      groupType: '',
      groupList: []
    }
  },

  onLoad(e) {
    console.log('-----------3-----------',e)
    this.groupType = e.group
    this.fetchNews();
  },
  methods: {
    onBtnClick(item) {
      console.log('-----------2-----------',item.title)
          uni.navigateTo({
       url: '/pages/rich/index?title=' + encodeURIComponent(item.title) + '&content=' + encodeURIComponent(item.content)
      });
    },
    goBack() {
      uni.navigateBack({
        delta: 1
      })
    },
    async fetchNews() {
      let urlstr;
      if (this.groupType == 'AB组') {
        urlstr = 'http://chaoxiang.scoringchina.com/index/api/group_ab';
      } else { 
        urlstr = 'http://chaoxiang.scoringchina.com/index/api/group_cd';
      }
      try {
        const res = await uni.request({
          url: urlstr,
          method: 'GET'
        });
        if(res && res.data && res.data.code === 1) {
          this.groupList = res.data.data || [];
          console.log('-----------4-----------',this.groupList)
        } else {
          console.error('获取数据失败', res[1]);
        }
      } catch (error) {
        console.error('请求异常', error);
      }
    },
  
  }
}
</script>
<style>
.btn-list {
  margin-top: 24rpx;
  display: flex;
  flex-direction: column;
  gap: 24rpx;
  padding: 0 24rpx;
}
.btn-item {
  min-height: 120rpx;
  border-radius: 20rpx;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 4rpx 16rpx rgba(0,0,0,0.08);
  position: relative;
  overflow: hidden;
}
.btn-label {
  font-size: 38rpx;
  color: #fff;
  font-weight: bold;
  letter-spacing: 2rpx;
}
.btn-icon {
  width: 704rpx;
  height: 291rpx;
}
</style>